<?php
declare(strict_types=1);

namespace App\ZxAdmin\Usercenter;

use App\Controller;
use Field\SysTakeConst;
use Field\SysTakeColumns;
use Field\SysTakeRow;

// hook controller_zx_admin_user_center_sys_take_use.php

/**
 * @title   操作日志
 * @auth    false
 * @login   true
 * @menu    false
 * @component   vlist/index.vue
 * @icon    el-icon-menu
 * @active  true
 * @affix   false
 * @rank    99
 */
class SysTake extends Controller
{
    // hook controller_zx_admin_user_center_sys_take_public_start.php

    // make public SysTake ZxAdmin\UserCenter
    /*
    protected array $echo_field 	=	['SysTake.1'=>['TakeID','UserID','CreateAt','Status','IP','Node','Take'],'SysUser.2'=>['UserID','UserName']];
    protected array $edit_field	    =	[];
    protected array $add_field      =	[];
    protected array $field_fields_kv	=	[];
    protected array $Columns	    =	[['table'=>'SysTake.1','prop'=>'TakeID','label'=>'操作记录ID','options'=>['remote'=>['api'=>'','name'=>''],'items'=>''],'search'=>0],['table'=>'SysTake.1','prop'=>'UserID','label'=>'用户ID','options'=>['remote'=>['api'=>'','name'=>''],'items'=>''],'search'=>1],['table'=>'SysTake.1','prop'=>'CreateAt','label'=>'操作时间','options'=>['remote'=>['api'=>'','name'=>''],'items'=>''],'search'=>1],['table'=>'SysTake.1','prop'=>'Status','label'=>'1成功0失败','options'=>['remote'=>['api'=>'','name'=>''],'items'=>'']],['table'=>'SysTake.1','prop'=>'IP','label'=>'IP地址','options'=>['remote'=>['api'=>'','name'=>''],'items'=>'']],['table'=>'SysTake.1','prop'=>'Node','label'=>'Node','options'=>['remote'=>['api'=>'','name'=>''],'items'=>''],'search'=>1],['table'=>'SysTake.1','prop'=>'Take','label'=>'操作内容','options'=>['remote'=>['api'=>'','name'=>''],'items'=>'']],['table'=>'SysUser.2','prop'=>'UserID','label'=>'会员ID','options'=>['remote'=>['api'=>'','name'=>''],'items'=>'']],['table'=>'SysUser.2','prop'=>'UserName','label'=>'账户','options'=>['remote'=>['api'=>'','name'=>''],'items'=>'']]];
    */
    public const make = 1;
    /**
     * @title   列表配置
     */
    public const Conf = [
        'pageSize' => 25,
        'pageSizes' => [10, 20, 30, 40, 50],
        'remoteSort'=>1,
        'remoteFilter'=>1,
        'remoteSummary'=>0,
        'hidePagination'=>0,
        'hideRefresh'=>0,
        'hideSetting'=>0,
        'hideDo'=>0,
        'add'=>0,
        'start'=>0,
        'stop'=>0,
        'delete'=>0,
        'import'=>0,
        'export'=>0
    ];
    /**
     * @title   列操作
     */
    public const Tools =[];
   /**
    * @title   列配置
    */
    public const Columns =[['table'=>'SysTake.1','prop'=>'TakeID','label'=>'操作记录ID','options'=>['remote'=>['api'=>'','name'=>''],'items'=>''],'search'=>0],['table'=>'SysTake.1','prop'=>'UserID','label'=>'用户ID','options'=>['remote'=>['api'=>'','name'=>''],'items'=>''],'search'=>1],['table'=>'SysTake.1','prop'=>'CreateAt','label'=>'操作时间','options'=>['remote'=>['api'=>'','name'=>''],'items'=>''],'search'=>1],['table'=>'SysTake.1','prop'=>'Status','disabled'=>1,'type'=>'switch','label'=>'1成功0失败','options'=>['remote'=>['api'=>'','name'=>''],'items'=>'']],['table'=>'SysTake.1','prop'=>'IP','label'=>'IP地址','options'=>['remote'=>['api'=>'','name'=>''],'items'=>'']],['table'=>'SysTake.1','prop'=>'Node','label'=>'Node','options'=>['remote'=>['api'=>'','name'=>''],'items'=>''],'search'=>1],['table'=>'SysTake.1','prop'=>'Take','label'=>'操作内容','options'=>['remote'=>['api'=>'','name'=>''],'items'=>'']]];
    /**
     * @title   筛选
     */
    public const Filter =[['table'=>'SysTake.1','prop'=>'UserID','label'=>'用户ID','options'=>['remote'=>['api'=>'','name'=>''],'items'=>''],'search'=>1,'component'=>'tableselect'],['table'=>'SysTake.1','prop'=>'CreateAt','label'=>'操作时间','options'=>['remote'=>['api'=>'','name'=>''],'items'=>'','type'=>'datetimerange'],'search'=>1,'component'=>'date','mode'=>'BETWEEN'],['table'=>'SysTake.1','prop'=>'Node','label'=>'Node','options'=>['remote'=>['api'=>'','name'=>''],'items'=>''],'search'=>1,'component'=>'input']];
    /**
     * @title   添加内容
     */
    public const AddForm =[];
    /**
     * @title   编辑内容
     */
    public const EditForm =[];

    // hook controller_zx_admin_user_center_sys_take_public_end.php

    /**
     * @title  下发配置
     * @rank    0
     */
    public function action_Conf_PUT()
    {
        // hook controller_zx_admin_user_center_sys_take_conf_start.php
        $data = [];
        $Columns = [];
        foreach (self::Columns as $row) {
            $Columns[] = $row;
        }
        /*

        $data['Column']=$this->Columns;
        $data['Tools'] = [];
        $Tools = [];
        foreach ($Tools as $k=> $row){
            switch ($row['do']){
                case 'add':
                case 'edit':
                case 'delete':
                case 'into':
                case 'start':
                case 'stop':
                    if($this->SysRoleAuth->Check($this->token->RoleID)){
                        $data['Tools'][]=$row;
                    }
                    break;
            }
        }
        */
        // make conf SysTake ZxAdmin\UserCenter
        // hook controller_zx_admin_user_center_sys_take_conf_end.php
        $this->response('0000', ['Conf' => self::Conf, 'Filter' => self::Filter, 'Tools' => self::Tools, 'Columns' => $Columns, 'data' => $data]);
    }

    /**
     * @title   下发列表数据
     * @rank    73
     */
    public function action_Index()
    {
        // hook controller_zx_admin_user_center_sys_take_index_start.php
        $page = $this->request->param('page', 0);
        $size = $this->request->param('limit', 0);
        $field = $this->request->param('field', '');
        $sort = $this->request->param('sort', '');
        $order = [];
        !empty($field) && $order[$field] = $sort == 'asc' ? -1 : 1;
        $cond = [];
        $UserID=$this->request->param('UserID',-1);
		$UserID>-1 && $cond['UserID']=$UserID;
		$CreateAt=$this->request->param('CreateAt');
		!empty($CreateAt) && $cond['CreateAt']=$CreateAt;
		$Node=$this->request->param('Node');
		!empty($Node) && $cond['Node']=$Node;
        $data = $this->SysTake->GetList($cond, $order, $page, $size);
        $rip2 = arrlist_values($data['data'],'UserID');
		$SysUser2 =!empty($rip2) ? $this->SysUser->select(['UserID'=>$rip2]):[];
        foreach ($data['data'] as &$row) {
            $row['SysUser.2.UserID'] =!empty($SysUser2[$row['UserID']]) ? $SysUser2[$row['UserID']]['UserID']:'';
		    $row['SysUser.2.UserName'] =!empty($SysUser2[$row['UserID']]) ? $SysUser2[$row['UserID']]['UserName']:'';
            //unset($row['PassWord'],$row['Salt']);
        }

        // hook controller_zx_admin_user_center_sys_take_index_end.php
        $this->response('0000', $data);
    }
    
    
    
    
     /**
      * @title   删除数据
      * @rank    50
      */
    public function action_Index_Delete()
    {
        // hook controller_zx_admin_user_center_sys_take_delete_start.php
        $data = $this->request->param('data', []);
        $this->CheckEmpty([$data], ['操作数据为空']);
        $r = $this->SysTake->deleteByIndex($data);
        // hook controller_zx_admin_user_center_sys_take_delete_end.php
        $this->response($r ? '0000' : '0001', ['data' => $r]);
    }
    
    
    /**
     * @title   启用
     * @rank    41
     */
    public function action_Enable_POST()
    {
        // hook controller_zx_admin_user_center_sys_take_enable_start.php
        $data = $this->request->param('data', []);
        $this->CheckEmpty([$data], ['操作数据为空']);
        $r = $this->SysTake->updateByIndex($data, [SysTakeConst::Status => 1]);
        // hook controller_zx_admin_user_center_sys_take_enable_end.php
        $this->response($r ? '0000' : '0001', ['data' => $r]);
    }

    /**
     * @title   禁用
     * @rank    40
     */
    public function action_Disable_POST()
    {
        // hook controller_zx_admin_user_center_sys_take_disable_start.php
        $data = $this->request->param('data', []);
        $this->CheckEmpty([$data], ['操作数据为空']);
        $r = $this->SysTake->updateByIndex($data, [SysTakeConst::Status => 0]);
        // hook controller_zx_admin_user_center_sys_take_disable_end.php
        $this->response($r ? '0000' : '0001', ['data' => $r]);
    }

    // hook controller_zx_admin_user_center_sys_take_end.php
}

?>